package com.smart.manage.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.smart.system.mapper.SysUserRoleMapper;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.smart.common.annotation.Log;
import com.smart.common.core.controller.BaseController;
import com.smart.common.core.domain.AjaxResult;
import com.smart.common.enums.BusinessType;
import com.smart.manage.domain.PatientsAppointment;
import com.smart.manage.service.IPatientsAppointmentService;
import com.smart.common.utils.poi.ExcelUtil;
import com.smart.common.core.page.TableDataInfo;

/**
 * 就诊人预约挂号Controller
 * 
 * @author lingyao
 * @date 2025-03-01
 */
@RestController
@RequestMapping("/manage/patientsAppointment")
public class PatientsAppointmentController extends BaseController
{
    @Autowired
    private IPatientsAppointmentService patientsAppointmentService;

    /**
     * 查询就诊人预约挂号列表
     */
    @PreAuthorize("@ss.hasPermi('manage:patientsAppointment:list')")
    @GetMapping("/list")
    public TableDataInfo list(PatientsAppointment patientsAppointment)
    {
        startPage();
        List<PatientsAppointment> list = patientsAppointmentService.selectPatientsAppointmentList(patientsAppointment);
        return getDataTable(list);
    }

    /**
     * 导出就诊人预约挂号列表
     */
    @PreAuthorize("@ss.hasPermi('manage:patientsAppointment:export')")
    @Log(title = "就诊人预约挂号", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, PatientsAppointment patientsAppointment)
    {
        List<PatientsAppointment> list = patientsAppointmentService.selectPatientsAppointmentList(patientsAppointment);
        ExcelUtil<PatientsAppointment> util = new ExcelUtil<PatientsAppointment>(PatientsAppointment.class);
        util.exportExcel(response, list, "就诊人预约挂号数据");
    }

    /**
     * 获取就诊人预约挂号详细信息
     */
    @PreAuthorize("@ss.hasPermi('manage:patientsAppointment:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(patientsAppointmentService.selectPatientsAppointmentById(id));
    }

    /**
     * 新增就诊人预约挂号
     */
    @PreAuthorize("@ss.hasPermi('manage:patientsAppointment:add')")
    @Log(title = "就诊人预约挂号", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody PatientsAppointment patientsAppointment)
    {
        Long userId = getUserId();
        patientsAppointment.setUserId(userId);
        // 当用户预约挂号的时候，设置默认的预约状态为已预约
        patientsAppointment.setStatus(0L);
        return toAjax(patientsAppointmentService.insertPatientsAppointment(patientsAppointment));
    }

    /**
     * 修改就诊人预约挂号
     */
    @PreAuthorize("@ss.hasPermi('manage:patientsAppointment:edit')")
    @Log(title = "就诊人预约挂号", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody PatientsAppointment patientsAppointment)
    {
        return toAjax(patientsAppointmentService.updatePatientsAppointment(patientsAppointment));
    }

    /**
     * 删除就诊人预约挂号
     */
    @PreAuthorize("@ss.hasPermi('manage:patientsAppointment:remove')")
    @Log(title = "就诊人预约挂号", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(patientsAppointmentService.deletePatientsAppointmentByIds(ids));
    }
}
